package com.example.dbcms.service.impl;

import com.example.dbcms.domain.Role;
import com.example.dbcms.mapper.RoleDao;
import com.example.dbcms.service.RoleService;
import com.example.dbcms.utils.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleDao roleDao;

    @Override
    public PageInfo<Role> selectAllRole(Role role) {
        PageHelper.startPage(role.getPageNum(),10);
        List<Role> roleList = roleDao.getRoleList(role);
        PageInfo<Role> rolePageInfo = new PageInfo<>(roleList);
        return rolePageInfo;
    }

    @Override
    public int addRole(Role role) {
        role.setId(roleDao.getMaxId()+1);
        role.setCreateTime(DateUtil.getCurrentDate());
        return roleDao.addRole(role);
    }

    @Override
    public int deleteRole(int id) {
        return roleDao.deleteRole(id);
    }

    @Override
    public int deleteMultipleRole(List<Integer> ids) {
        return roleDao.deleteMultipleRole(ids);
    }

    @Override
    public Role getRoleById(int id) {
        return roleDao.getRoleById(id);
    }

    @Override
    public int updateRole(Role role) {
        return roleDao.updateRole(role);
    }
}
